package com.playball.lottery.frm.buyhall;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoListByType;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.frm.yhzx.ZhRecordActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.DynArrayInt;
import com.playball.lottery.util.SensorListener;
import com.playball.lottery.util.SoundManage;
import com.playball.lottery.util.SysApplication;


public class Pailie5xhActivity extends BaseActivity implements DefConstants {
	/** 上下文内容 */
	private Context context = null;
	public Button iBt_00, iBt_01, iBt_02, iBt_03, iBt_04, iBt_05, iBt_06, iBt_07, iBt_08, iBt_09;
	public Button iBt_b_00, iBt_b_01, iBt_b_02, iBt_b_03, iBt_b_04, iBt_b_05, iBt_b_06, iBt_b_07, iBt_b_08, iBt_b_09;
	public Button iBt_c_00, iBt_c_01, iBt_c_02, iBt_c_03, iBt_c_04, iBt_c_05, iBt_c_06, iBt_c_07, iBt_c_08, iBt_c_09;
	public Button iBt_d_00, iBt_d_01, iBt_d_02, iBt_d_03, iBt_d_04, iBt_d_05, iBt_d_06, iBt_d_07, iBt_d_08, iBt_d_09;
	public Button iBt_e_00, iBt_e_01, iBt_e_02, iBt_e_03, iBt_e_04, iBt_e_05, iBt_e_06, iBt_e_07, iBt_e_08, iBt_e_09;
	private Button buy_pl5_random;// 机选红球
	private Button buy_pl5_clear;// 清空选择
	private Button buy_pl5_submit;// 确认选择
	private TextView currentIssue;// 当前期次
	private TextView endTimeText;// 截至时间
	private TextView countText;// 倍数
	private TextView moneyText;
	/** 彩种ID */
	private int lotID;
	/** 结束时间 */
	private long endTime;
	/** 玩法ID */
	private int playTypeId;
	private int count;
	private int allMoney;
	/** 当前期次编号 */
	private String issueID;
	/** 当前期次名称 */
	private String issueName;
	private PopupWindow m_popupWindow;
	boolean flag = false;
	private DynArrayInt ball_1st_dintInt;
	private DynArrayInt ball_2nd_dintInt;
	private DynArrayInt ball_3rd_dintInt;
	private DynArrayInt ball_4th_dintInt;
	private DynArrayInt ball_5th_dintInt;
	Handler handler = new Handler();
	private SensorListener sensor;
	/** .若中奖：奖金0元，盈利0元 */
	private TextView tvJiangJin;
	/** 摇一摇机选一注视图 */
	private LinearLayout buy_ssq_llfoot0;
	/** 注数金额 */
	private RelativeLayout buy_ssq_rlfoot1;
	/** 点击此处可以弹出下拉10期开奖 */
	private LinearLayout buy_ssqxh_llxiala;
	/** 下拉10期开奖详情 */
	private LinearLayout buy_ssqxh_ll10kjdetail;
	/** 下拉10期开奖详情 */
	private List<Map<String, Object>> kjData;
	/** 判断是否从选号列表过来 */
	private Boolean ifbacklist;
	/** 判断是否从推送通知过来 */
	private Boolean ifPush;
	private LinearLayout buy_ssqxh_Button03,buy_ssqxh_Button04;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.buy_pl5);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
						| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		SysApplication.getInstance().addActivity(this);
		TitleBar();

		Intent intent = getIntent();
		lotID = LOT_ID_PL5;
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		endTime = intent.getLongExtra("EndTime", 0);
		ifbacklist = intent.getBooleanExtra("ifbacklist", false);
		ifPush = intent.getBooleanExtra("ifPush", false);
		Log.e("", "issueID=" + issueID);
		Log.e("", "issueName=" + issueName);
		Log.e("", "endTime=" + endTime);
		playTypeId = PL5_ZX_F;

		kaijiangAsyncLoader task = new kaijiangAsyncLoader();
		task.execute(LOT_ID_PL5 + "", "301");

		initView();

		currentIssue.setText(issueName);

		handler.postDelayed(runnable, 1000);

		AsyncLoader task1 = new AsyncLoader();
		String[] parms = new String[2];
		parms[0] = "200";
		JSONObject jsob = new JSONObject();
		try {
			// 设置请求所需参数
			jsob.put("LottID", LOT_ID_PL5);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		parms[1] = jsob.toString();
		task1.execute(parms);

		int isfromkaiJiang = intent.getIntExtra("isfromkaiJiang", 0);
		if (isfromkaiJiang == 1 || !ifbacklist ) {
			initBall();
			ball_1st_dintInt = new DynArrayInt();
			ball_2nd_dintInt = new DynArrayInt();
			ball_3rd_dintInt = new DynArrayInt();
			ball_4th_dintInt = new DynArrayInt();
			ball_5th_dintInt = new DynArrayInt();

			ball_2nd_dintInt.removeAll();
			ball_3rd_dintInt.removeAll();
			ball_1st_dintInt.removeAll();
			ball_4th_dintInt.removeAll();
			ball_5th_dintInt.removeAll();

			if (playTypeId == PL5_ZX_F) {// 直选
				ball_1st_dintInt.addInt(RandomGenData(0, 9, 1, "first"));
				ball_2nd_dintInt.addInt(RandomGenData(0, 9, 1, "second"));
				ball_3rd_dintInt.addInt(RandomGenData(0, 9, 1, "third"));
				ball_4th_dintInt.addInt(RandomGenData(0, 9, 1, "forth"));
				ball_5th_dintInt.addInt(RandomGenData(0, 9, 1, "fifth"));
			}

			getMoneyInfo();
		}

		// 下拉10期开奖
		buy_ssqxh_llxiala.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				doKaiJiang();
			}
		});

		buy_ssqxh_ll10kjdetail.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_ssqxh_ll10kjdetail.getVisibility() == View.VISIBLE) {
					buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
				}
			}
		});

		// 清空选择
		buy_pl5_clear.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ball_1st_dintInt.getSize() != 0) {
					initBall();
					allMoney = 0;
					count = 0;
					moneyText.setText("0");
					countText.setText("0");
					tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
					buy_ssq_llfoot0.setVisibility(View.VISIBLE);
					buy_ssq_rlfoot1.setVisibility(View.GONE);
				} else {
					Toast.makeText(Pailie5xhActivity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
					initBall();
				}
			}
		});

		// 机选
		buy_pl5_random.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initBall();
				ball_1st_dintInt = new DynArrayInt();
				ball_2nd_dintInt = new DynArrayInt();
				ball_3rd_dintInt = new DynArrayInt();
				ball_4th_dintInt = new DynArrayInt();
				ball_5th_dintInt = new DynArrayInt();

				ball_2nd_dintInt.removeAll();
				ball_3rd_dintInt.removeAll();
				ball_1st_dintInt.removeAll();
				ball_4th_dintInt.removeAll();
				ball_5th_dintInt.removeAll();

				if (playTypeId == PL5_ZX_F) {// 直选
					ball_1st_dintInt.addInt(RandomGenData(0, 9, 1, "first"));
					ball_2nd_dintInt.addInt(RandomGenData(0, 9, 1, "second"));
					ball_3rd_dintInt.addInt(RandomGenData(0, 9, 1, "third"));
					ball_4th_dintInt.addInt(RandomGenData(0, 9, 1, "forth"));
					ball_5th_dintInt.addInt(RandomGenData(0, 9, 1, "fifth"));
				}

				getMoneyInfo();
			}
		});

		// 确认选择，跳转至ElvSelFiveListbActivity.class
		buy_pl5_submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				goXhlbSubmit();
			}
		});

		// 晃动机选号码
		sensor = new SensorListener(this);
		sensor.setOnSensorListener(new SensorListener.OnSensorListener() {
			@Override
			public void onShake() {

				// TODO Auto-generated method stub
				SoundManage.OnVibator(Pailie5xhActivity.this, 500);
				initBall();
				ball_1st_dintInt = new DynArrayInt();
				ball_2nd_dintInt = new DynArrayInt();
				ball_3rd_dintInt = new DynArrayInt();
				ball_4th_dintInt = new DynArrayInt();
				ball_5th_dintInt = new DynArrayInt();

				ball_2nd_dintInt.removeAll();
				ball_3rd_dintInt.removeAll();
				ball_1st_dintInt.removeAll();
				ball_4th_dintInt.removeAll();
				ball_5th_dintInt.removeAll();

				if (playTypeId == PL5_ZX_F) {// 直选
					ball_1st_dintInt.addInt(RandomGenData(0, 9, 1, "first"));
					ball_2nd_dintInt.addInt(RandomGenData(0, 9, 1, "second"));
					ball_3rd_dintInt.addInt(RandomGenData(0, 9, 1, "third"));
					ball_4th_dintInt.addInt(RandomGenData(0, 9, 1, "forth"));
					ball_5th_dintInt.addInt(RandomGenData(0, 9, 1, "fifth"));
				}
				getMoneyInfo();
				// SoundManage.OnPlaySound(SsqxhActivity.this, "audio.mp3");
			}
		});

	}

	/**
	 * 开奖栏点击 事件
	 */
	protected void doKaiJiang() {
		if (kjData != null && buy_ssqxh_ll10kjdetail.getVisibility() == View.GONE) {
			buy_ssqxh_ll10kjdetail.setVisibility(View.VISIBLE);
			TextView buy_ssq_10qikj_tvqici1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici1);
			TextView buy_ssq_10qikj_tvqici2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici2);
			TextView buy_ssq_10qikj_tvqici3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici3);
			TextView buy_ssq_10qikj_tvqici4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici4);
			TextView buy_ssq_10qikj_tvqici5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici5);
			TextView buy_ssq_10qikj_tvqici6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici6);
			TextView buy_ssq_10qikj_tvqici7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici7);
			TextView buy_ssq_10qikj_tvqici8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici8);
			TextView buy_ssq_10qikj_tvqici9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici9);
			TextView buy_ssq_10qikj_tvqici10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici10);

			TextView buy_ssq_10qikj_tvred1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred1);
			TextView buy_ssq_10qikj_tvred2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred2);
			TextView buy_ssq_10qikj_tvred3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred3);
			TextView buy_ssq_10qikj_tvred4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred4);
			TextView buy_ssq_10qikj_tvred5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred5);
			TextView buy_ssq_10qikj_tvred6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred6);
			TextView buy_ssq_10qikj_tvred7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred7);
			TextView buy_ssq_10qikj_tvred8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred8);
			TextView buy_ssq_10qikj_tvred9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred9);
			TextView buy_ssq_10qikj_tvred10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred10);

			TextView buy_ssq_10qikj_tvblue1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue1);
			TextView buy_ssq_10qikj_tvblue2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue2);
			TextView buy_ssq_10qikj_tvblue3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue3);
			TextView buy_ssq_10qikj_tvblue4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue4);
			TextView buy_ssq_10qikj_tvblue5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue5);
			TextView buy_ssq_10qikj_tvblue6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue6);
			TextView buy_ssq_10qikj_tvblue7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue7);
			TextView buy_ssq_10qikj_tvblue8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue8);
			TextView buy_ssq_10qikj_tvblue9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue9);
			TextView buy_ssq_10qikj_tvblue10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue10);

			if (kjData != null && kjData.size() > 0) {
				buy_ssq_10qikj_tvqici1.setText(kjData.get(0).get("Issue").toString());
				buy_ssq_10qikj_tvred1.setText(kjData.get(0).get("Ball").toString());
				if (kjData.size() > 1) {
					buy_ssq_10qikj_tvqici2.setText(kjData.get(1).get("Issue").toString());
					buy_ssq_10qikj_tvred2.setText(kjData.get(1).get("Ball").toString());
				}
				if (kjData.size() > 2) {
					buy_ssq_10qikj_tvqici3.setText(kjData.get(2).get("Issue").toString());
					buy_ssq_10qikj_tvred3.setText(kjData.get(2).get("Ball").toString());
				}
				if (kjData.size() > 3) {
					buy_ssq_10qikj_tvqici4.setText(kjData.get(3).get("Issue").toString());
					buy_ssq_10qikj_tvred4.setText(kjData.get(3).get("Ball").toString());
				}
				if (kjData.size() > 4) {
					buy_ssq_10qikj_tvqici5.setText(kjData.get(4).get("Issue").toString());
					buy_ssq_10qikj_tvred5.setText(kjData.get(4).get("Ball").toString());
				}
				if (kjData.size() > 5) {
					buy_ssq_10qikj_tvqici6.setText(kjData.get(5).get("Issue").toString());
					buy_ssq_10qikj_tvred6.setText(kjData.get(5).get("Ball").toString());
				}
				if (kjData.size() > 6) {
					buy_ssq_10qikj_tvqici7.setText(kjData.get(6).get("Issue").toString());
					buy_ssq_10qikj_tvred7.setText(kjData.get(6).get("Ball").toString());
				}
				if (kjData.size() > 7) {
					buy_ssq_10qikj_tvqici8.setText(kjData.get(7).get("Issue").toString());
					buy_ssq_10qikj_tvred8.setText(kjData.get(7).get("Ball").toString());
				}
				if (kjData.size() > 8) {
					buy_ssq_10qikj_tvqici9.setText(kjData.get(8).get("Issue").toString());
					buy_ssq_10qikj_tvred9.setText(kjData.get(8).get("Ball").toString());
				}
				if (kjData.size() > 9) {
					buy_ssq_10qikj_tvqici10.setText(kjData.get(9).get("Issue").toString());
					buy_ssq_10qikj_tvred10.setText(kjData.get(9).get("Ball").toString());
				}

				if (kjData.get(0).get("BlueBall") != null && !"".equals(kjData.get(0).get("BlueBall").toString())) {
					buy_ssq_10qikj_tvblue1.setText(kjData.get(0).get("BlueBall").toString());
					if (kjData.size() > 1) {
						buy_ssq_10qikj_tvblue2.setText(kjData.get(1).get("BlueBall").toString());
					}
					if (kjData.size() > 2) {
						buy_ssq_10qikj_tvblue3.setText(kjData.get(2).get("BlueBall").toString());
					}
					if (kjData.size() > 3) {
						buy_ssq_10qikj_tvblue4.setText(kjData.get(3).get("BlueBall").toString());
					}
					if (kjData.size() > 4) {
						buy_ssq_10qikj_tvblue5.setText(kjData.get(4).get("BlueBall").toString());
					}
					if (kjData.size() > 5) {
						buy_ssq_10qikj_tvblue6.setText(kjData.get(5).get("BlueBall").toString());
					}
					if (kjData.size() > 6) {
						buy_ssq_10qikj_tvblue7.setText(kjData.get(6).get("BlueBall").toString());
					}
					if (kjData.size() > 7) {
						buy_ssq_10qikj_tvblue8.setText(kjData.get(7).get("BlueBall").toString());
					}
					if (kjData.size() > 8) {
						buy_ssq_10qikj_tvblue9.setText(kjData.get(8).get("BlueBall").toString());
					}
					if (kjData.size() > 9) {
						buy_ssq_10qikj_tvblue10.setText(kjData.get(9).get("BlueBall").toString());
					}
				} else {
					TextView buy_10qikj_tvfh1 = (TextView) findViewById(R.id.buy_10qikj_tvfh1);
					TextView buy_10qikj_tvfh2 = (TextView) findViewById(R.id.buy_10qikj_tvfh2);
					TextView buy_10qikj_tvfh3 = (TextView) findViewById(R.id.buy_10qikj_tvfh3);
					TextView buy_10qikj_tvfh4 = (TextView) findViewById(R.id.buy_10qikj_tvfh4);
					TextView buy_10qikj_tvfh5 = (TextView) findViewById(R.id.buy_10qikj_tvfh5);
					TextView buy_10qikj_tvfh6 = (TextView) findViewById(R.id.buy_10qikj_tvfh6);
					TextView buy_10qikj_tvfh7 = (TextView) findViewById(R.id.buy_10qikj_tvfh7);
					TextView buy_10qikj_tvfh8 = (TextView) findViewById(R.id.buy_10qikj_tvfh8);
					TextView buy_10qikj_tvfh9 = (TextView) findViewById(R.id.buy_10qikj_tvfh9);
					TextView buy_10qikj_tvfh10 = (TextView) findViewById(R.id.buy_10qikj_tvfh10);
					buy_10qikj_tvfh1.setVisibility(View.GONE);
					buy_10qikj_tvfh2.setVisibility(View.GONE);
					buy_10qikj_tvfh3.setVisibility(View.GONE);
					buy_10qikj_tvfh4.setVisibility(View.GONE);
					buy_10qikj_tvfh5.setVisibility(View.GONE);
					buy_10qikj_tvfh6.setVisibility(View.GONE);
					buy_10qikj_tvfh7.setVisibility(View.GONE);
					buy_10qikj_tvfh8.setVisibility(View.GONE);
					buy_10qikj_tvfh9.setVisibility(View.GONE);
					buy_10qikj_tvfh10.setVisibility(View.GONE);

					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue2.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue3.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue4.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue5.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue6.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue7.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue8.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue9.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue10.setVisibility(View.GONE);
				}
			}
		} else {
			if(buy_ssqxh_ll10kjdetail.getVisibility()==View.VISIBLE){
				buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
			}else {
				Toast.makeText(this,"无往期开奖信息",Toast.LENGTH_SHORT).show();
			}
		}
	}

	public void sendIntent(BallDTO elvdto, String ball) {
		elvdto.setPl5_ball(ball + "-" + allMoney);

		// 新选的号码，追加在ApplicationBall全局变量list_ssqdto里
		ApplicationData.getInstance().getList_pl5dto().add(elvdto);
		ApplicationData.getInstance().setAll_pl5money(ApplicationData.getInstance().getAll_pl5money() + allMoney);
		ApplicationData.getInstance().setPlay_pl5Id(playTypeId);

		Intent intent = new Intent();
		intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_pl5dto());
		intent.putExtra("PlayTypeID", playTypeId);
		// intent.putExtra("PlayType", playType.getSelectedItem().toString());
		intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_pl5money());
		intent.putExtra("LotID", lotID);
		intent.putExtra("Count", count);
		intent.putExtra("IssueID", issueID);
		intent.putExtra("IssueName", issueName);
		intent.setClass(Pailie5xhActivity.this, Pailie5ListActivity.class);
		startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
		finish();
	}

	// 随机取球，并显示
	public int[] RandomGenData(int min, int max, int num, String position) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[num];
		List<Integer> a1 = new ArrayList<Integer>();
		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}
		for (int i = 0; i < num; i++) {
			int index = rndNumber.nextInt(max - min + 1 - i);
			Object o = a1.get(index);
			temp[i] = ((Integer) o).intValue();
			if (position.equals("first"))
				BallRandom(1, 0, 0, 0, 0, temp[i]);
			if (position.equals("second"))
				BallRandom(0, 1, 0, 0, 0, temp[i]);
			if (position.equals("third"))
				BallRandom(0, 0, 1, 0, 0, temp[i]);
			if (position.equals("forth"))
				BallRandom(0, 0, 0, 1, 0, temp[i]);
			if (position.equals("fifth"))
				BallRandom(0, 0, 0, 0, 1, temp[i]);
			a1.remove(index);
		}
		Arrays.sort(temp);
		return temp;
	}

	public void BallRandom(int a, int b, int c, int d, int e, int num) {
		if (num == 0 && a == 1) {
			iBt_00.setSelected(true);
		}
		if (num == 1 && a == 1) {
			iBt_01.setSelected(true);
		}
		if (num == 2 && a == 1) {
			iBt_02.setSelected(true);
		}
		if (num == 3 && a == 1) {
			iBt_03.setSelected(true);
		}
		if (num == 4 && a == 1) {
			iBt_04.setSelected(true);
		}
		if (num == 5 && a == 1) {
			iBt_05.setSelected(true);
		}
		if (num == 6 && a == 1) {
			iBt_06.setSelected(true);
		}
		if (num == 7 && a == 1) {
			iBt_07.setSelected(true);
		}
		if (num == 8 && a == 1) {
			iBt_08.setSelected(true);
		}
		if (num == 9 && a == 1) {
			iBt_09.setSelected(true);
		}

		if (num == 0 && b == 1) {
			iBt_b_00.setSelected(true);

		}
		if (num == 1 && b == 1) {
			iBt_b_01.setSelected(true);

		}
		if (num == 2 && b == 1) {
			iBt_b_02.setSelected(true);
		}
		if (num == 3 && b == 1) {
			iBt_b_03.setSelected(true);
		}
		if (num == 4 && b == 1) {
			iBt_b_04.setSelected(true);
		}
		if (num == 5 && b == 1) {
			iBt_b_05.setSelected(true);
		}
		if (num == 6 && b == 1) {
			iBt_b_06.setSelected(true);
		}
		if (num == 7 && b == 1) {
			iBt_b_07.setSelected(true);
		}
		if (num == 8 && b == 1) {
			iBt_b_08.setSelected(true);
		}
		if (num == 9 && b == 1) {
			iBt_b_09.setSelected(true);
		}

		if (num == 0 && c == 1) {
			iBt_c_00.setSelected(true);
		}
		if (num == 1 && c == 1) {
			iBt_c_01.setSelected(true);
		}
		if (num == 2 && c == 1) {
			iBt_c_02.setSelected(true);
		}
		if (num == 3 && c == 1) {
			iBt_c_03.setSelected(true);
		}
		if (num == 4 && c == 1) {
			iBt_c_04.setSelected(true);
		}
		if (num == 5 && c == 1) {
			iBt_c_05.setSelected(true);
		}
		if (num == 6 && c == 1) {
			iBt_c_06.setSelected(true);
		}
		if (num == 7 && c == 1) {
			iBt_c_07.setSelected(true);
		}
		if (num == 8 && c == 1) {
			iBt_c_08.setSelected(true);
		}
		if (num == 9 && c == 1) {
			iBt_c_09.setSelected(true);
		}
		if (d == 1) {
			switch (num) {
			case 0:
				iBt_d_00.setSelected(true);
				break;
			case 1:
				iBt_d_01.setSelected(true);
				break;
			case 2:
				iBt_d_02.setSelected(true);
				break;
			case 3:
				iBt_d_03.setSelected(true);
				break;
			case 4:
				iBt_d_04.setSelected(true);
				break;
			case 5:
				iBt_d_05.setSelected(true);
				break;
			case 6:
				iBt_d_06.setSelected(true);
				break;
			case 7:
				iBt_d_07.setSelected(true);
				break;
			case 8:
				iBt_d_08.setSelected(true);
				break;
			case 9:
				iBt_d_09.setSelected(true);
				break;
			}
		}
		if (e == 1) {
			switch (num) {
			case 0:
				iBt_e_00.setSelected(true);
				break;
			case 1:
				iBt_e_01.setSelected(true);
				break;
			case 2:
				iBt_e_02.setSelected(true);
				break;
			case 3:
				iBt_e_03.setSelected(true);
				break;
			case 4:
				iBt_e_04.setSelected(true);
				break;
			case 5:
				iBt_e_05.setSelected(true);
				break;
			case 6:
				iBt_e_06.setSelected(true);
				break;
			case 7:
				iBt_e_07.setSelected(true);
				break;
			case 8:
				iBt_e_08.setSelected(true);
				break;
			case 9:
				iBt_e_09.setSelected(true);
				break;
			}
		}
	}

	// 倒计时
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			getCountDown(endTime--);
			handler.postDelayed(this, 1000);
		}
	};

	private void getCountDown(long end) {
		if (end > 0) {
			String res = "";
			long temp = 0;
			long d = end / 86400;
			temp = end - (d * 86400);
			if (d > 0) {
				res += d + "天";
			}

			long h = temp / 3600;
			if (h > 0) {
				res += h + "时";
			}
			temp = temp - (h * 3600);

			long m = temp / 60;
			if (h > 0) {
				res += m + "分";
			} else if (h == 0 && m > 0) {
				res += m + "分";
			}
			temp = temp - (m * 60);

			long s = temp;
			res += s + "秒";
			endTimeText.setText(res);
		} else {
			endTimeText.setText("----------");
			/*
			 * AsyncLoader task = new AsyncLoader(); String[] parms = new
			 * String[2]; parms[0] = "200"; JSONObject jsob = new JSONObject();
			 * try { // 设置请求所需参数 jsob.put("LottID", LOT_ID_PL5); } catch
			 * (JSONException ex) { // TODO Auto-generated catch block
			 * Log.e("error", ex.toString()); } parms[1] = jsob.toString();
			 * task.execute(parms);
			 */

		}
	}

	private List<Map<String, Object>> mData;
	private Map<String, Object> cData;

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		int id;

		// 1.准备运行
		protected void onPreExecute() {
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			// 处理后台执行的任务，在后台线程执行
			String strResult;
			// 设置请求action
			String action = params[0];
			// 获取请求返回值
			strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {

				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						mData = getData(result);
						for (int i = 0; i < mData.size(); i++) {
							id = Integer.parseInt(mData.get(i).get("LotID").toString());
							cData = mData.get(i);
							switch (id) {
							case 64:
								issueID = cData.get("IssueID").toString();
								issueName = cData.get("IssueName").toString();
								endTime = setEndTime(cData);
								currentIssue.setText(issueName);
							}
						}
					} else {
						Toast.makeText(Pailie5xhActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				}
			} else {
				Toast.makeText(Pailie5xhActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	/**
	 * 
	 * 获取开奖数据
	 * 
	 */
	public class kaijiangAsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		// 1.准备运行
		protected void onPreExecute() {
			// showdialog.showDialog(KjinfoListByType.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			String strResult;
			try {
				// 处理后台执行的任务，在后台线程执行
				JSONObject param = new JSONObject();
				param.put("LottID", params[0]);
				// 设置请求action
				String action = params[1];
				// 获取请求返回值
				strResult = GetRequestParams.getRequestResult(param.toString(), action, getApplicationContext());
				return strResult;
			} catch (Exception e) {
				// TODO: handle exception
				Log.e("error", e.toString());
				return null;
			}
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// Toast.LENGTH_LONG).show();
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (!"".equals(js.getString("Data"))&&!"[]".equals(js.getString("Data"))) {
							kjData = getData(result);
							for (int i = 0; i < kjData.size(); i++) {
								String issue = kjData.get(i).get("Issue").toString();
								issue += "期";// = "期\t开奖号码"
								kjData.get(i).put("Issue", issue);
								String winNumber = kjData.get(i).get("WinNumber").toString();
								String[] nums = winNumber.split("\\+");
								// kjData.get(i).put("Ball", nums[0]);
								kjData.get(i).put("Ball", nums[0].replaceAll(",", " "));
								kjData.get(i).put("BlueBall", nums.length > 1 ? nums[1].trim() : "");
							}
							// Log.v("pl5xh", "kjData= "+kjData.toString());
							// KjInfoListAdapter adapter = new
							// KjInfoListAdapter(Fc3dxhActivity.this, mData);
							// buy_11x5_lv_kaijiang.setAdapter(adapter);
						} else {
						}
						// showdialog.closeDialog();
					} else {
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					// showdialog.closeDialog();
				}
			} else {
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			list = ConvertJsonToList.getList(js.getString("Data"));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}

		return list;
	}

	private long setEndTime(Map<String, Object> data) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long endTime = 0;
		try {
			long a = sdf.parse(data.get("CurrentTime").toString()).getTime();
			long b = sdf.parse(data.get("EndTime").toString()).getTime();
			endTime = (b - a) / 1000;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
		return endTime;
	}

	private void initView() {
		buy_ssq_llfoot0 = (LinearLayout) findViewById(R.id.buy_ssq_llfoot0);
		buy_ssq_rlfoot1 = (RelativeLayout) findViewById(R.id.buy_ssq_rlfoot1);
		buy_ssqxh_llxiala = (LinearLayout) findViewById(R.id.buy_ssqxh_llxiala);
		buy_ssqxh_ll10kjdetail = (LinearLayout) findViewById(R.id.buy_ssqxh_ll10kjdetail);
		buy_ssq_llfoot0.setVisibility(View.VISIBLE);
		buy_ssq_rlfoot1.setVisibility(View.GONE);
		// 初始化球
		initBall();
		// 初始化文本框
		initText();

		// 初始化button
		initButton();
	}

	public void initBall() {
		init1stBall();
		init2ndBall();
		init3rdBall();
		init_4th_ball();
		init_5th_ball();
	}

	public void init1stBall() {
		ball_1st_dintInt = new DynArrayInt();

		iBt_00 = (Button) findViewById(R.id.buy_pl3_imageButton00);
		iBt_00.setSelected(false);
		iBt_00.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_00.isSelected()) {
					iBt_00.setSelected(false);
					ball_1st_dintInt.remove(0);

				} else {
					iBt_00.setSelected(true);
					ball_1st_dintInt.addInt(0);

				}
				getMoneyInfo();
			}
		});

		iBt_01 = (Button) findViewById(R.id.buy_pl3_imageButton01);
		iBt_01.setSelected(false);
		iBt_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_01.isSelected()) {
					iBt_01.setSelected(false);
					ball_1st_dintInt.remove(1);

				} else {
					iBt_01.setSelected(true);
					ball_1st_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		iBt_02 = (Button) findViewById(R.id.buy_pl3_imageButton02);
		iBt_02.setSelected(false);
		iBt_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_02.isSelected()) {
					iBt_02.setSelected(false);
					ball_1st_dintInt.remove(2);

				} else {
					iBt_02.setSelected(true);
					ball_1st_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		iBt_03 = (Button) findViewById(R.id.buy_pl3_imageButton03);
		iBt_03.setSelected(false);
		iBt_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_03.isSelected()) {
					iBt_03.setSelected(false);
					ball_1st_dintInt.remove(3);

				} else {
					iBt_03.setSelected(true);
					ball_1st_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		iBt_04 = (Button) findViewById(R.id.buy_pl3_imageButton04);
		iBt_04.setSelected(false);
		iBt_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_04.isSelected()) {
					iBt_04.setSelected(false);
					ball_1st_dintInt.remove(4);

				} else {
					iBt_04.setSelected(true);
					ball_1st_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});
		iBt_05 = (Button) findViewById(R.id.buy_pl3_imageButton05);
		iBt_05.setSelected(false);
		iBt_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_05.isSelected()) {
					iBt_05.setSelected(false);
					ball_1st_dintInt.remove(5);

				} else {
					iBt_05.setSelected(true);
					ball_1st_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		iBt_06 = (Button) findViewById(R.id.buy_pl3_imageButton06);
		iBt_06.setSelected(false);
		iBt_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_06.isSelected()) {
					iBt_06.setSelected(false);
					ball_1st_dintInt.remove(6);

				} else {
					iBt_06.setSelected(true);
					ball_1st_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});

		iBt_07 = (Button) findViewById(R.id.buy_pl3_imageButton07);
		iBt_07.setSelected(false);
		iBt_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_07.isSelected()) {
					iBt_07.setSelected(false);
					ball_1st_dintInt.remove(7);

				} else {
					iBt_07.setSelected(true);
					ball_1st_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		iBt_08 = (Button) findViewById(R.id.buy_pl3_imageButton08);
		iBt_08.setSelected(false);
		iBt_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_08.isSelected()) {
					iBt_08.setSelected(false);
					ball_1st_dintInt.remove(8);

				} else {
					iBt_08.setSelected(true);
					ball_1st_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		iBt_09 = (Button) findViewById(R.id.buy_pl3_imageButton09);
		iBt_09.setSelected(false);
		iBt_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_09.isSelected()) {
					iBt_09.setSelected(false);
					ball_1st_dintInt.remove(9);

				} else {
					iBt_09.setSelected(true);
					ball_1st_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});
	}

	public void init2ndBall() {
		ball_2nd_dintInt = new DynArrayInt();

		iBt_b_00 = (Button) findViewById(R.id.buy_pl3_b_00);
		iBt_b_00.setSelected(false);
		iBt_b_00.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_00.isSelected()) {
					iBt_b_00.setSelected(false);
					ball_2nd_dintInt.remove(0);

				} else {
					iBt_b_00.setSelected(true);
					ball_2nd_dintInt.addInt(0);

				}
				getMoneyInfo();
			}
		});

		iBt_b_01 = (Button) findViewById(R.id.buy_pl3_b_01);
		iBt_b_01.setSelected(false);
		iBt_b_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_01.isSelected()) {
					iBt_b_01.setSelected(false);
					ball_2nd_dintInt.remove(1);

				} else {
					iBt_b_01.setSelected(true);
					ball_2nd_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		iBt_b_02 = (Button) findViewById(R.id.buy_pl3_b_02);
		iBt_b_02.setSelected(false);
		iBt_b_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_02.isSelected()) {
					iBt_b_02.setSelected(false);
					ball_2nd_dintInt.remove(2);

				} else {
					iBt_b_02.setSelected(true);
					ball_2nd_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		iBt_b_03 = (Button) findViewById(R.id.buy_pl3_b_03);
		iBt_b_03.setSelected(false);
		iBt_b_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_03.isSelected()) {
					iBt_b_03.setSelected(false);
					ball_2nd_dintInt.remove(3);

				} else {
					iBt_b_03.setSelected(true);
					ball_2nd_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		iBt_b_04 = (Button) findViewById(R.id.buy_pl3_b_04);
		iBt_b_04.setSelected(false);
		iBt_b_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_04.isSelected()) {
					iBt_b_04.setSelected(false);
					ball_2nd_dintInt.remove(4);

				} else {
					iBt_b_04.setSelected(true);
					ball_2nd_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		iBt_b_05 = (Button) findViewById(R.id.buy_pl3_b_05);
		iBt_b_05.setSelected(false);
		iBt_b_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_05.isSelected()) {
					iBt_b_05.setSelected(false);
					ball_2nd_dintInt.remove(5);

				} else {
					iBt_b_05.setSelected(true);
					ball_2nd_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		iBt_b_06 = (Button) findViewById(R.id.buy_pl3_b_06);
		iBt_b_06.setSelected(false);
		iBt_b_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_06.isSelected()) {
					iBt_b_06.setSelected(false);
					ball_2nd_dintInt.remove(6);

				} else {
					iBt_b_06.setSelected(true);
					ball_2nd_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});

		iBt_b_07 = (Button) findViewById(R.id.buy_pl3_b_07);
		iBt_b_07.setSelected(false);
		iBt_b_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_07.isSelected()) {
					iBt_b_07.setSelected(false);
					ball_2nd_dintInt.remove(7);

				} else {
					iBt_b_07.setSelected(true);
					ball_2nd_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		iBt_b_08 = (Button) findViewById(R.id.buy_pl3_b_08);
		iBt_b_08.setSelected(false);
		iBt_b_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_08.isSelected()) {
					iBt_b_08.setSelected(false);
					ball_2nd_dintInt.remove(8);

				} else {
					iBt_b_08.setSelected(true);
					ball_2nd_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		iBt_b_09 = (Button) findViewById(R.id.buy_pl3_b_09);
		iBt_b_09.setSelected(false);
		iBt_b_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_b_09.isSelected()) {
					iBt_b_09.setSelected(false);
					ball_2nd_dintInt.remove(9);

				} else {
					iBt_b_09.setSelected(true);
					ball_2nd_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

	}

	public void init3rdBall() {
		ball_3rd_dintInt = new DynArrayInt();

		iBt_c_00 = (Button) findViewById(R.id.buy_pl3_c_00);
		iBt_c_00.setSelected(false);
		iBt_c_00.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_00.isSelected()) {
					iBt_c_00.setSelected(false);
					ball_3rd_dintInt.remove(0);

				} else {
					iBt_c_00.setSelected(true);
					ball_3rd_dintInt.addInt(0);

				}
				getMoneyInfo();
			}
		});

		iBt_c_01 = (Button) findViewById(R.id.buy_pl3_c_01);
		iBt_c_01.setSelected(false);
		iBt_c_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_01.isSelected()) {
					iBt_c_01.setSelected(false);
					ball_3rd_dintInt.remove(1);

				} else {
					iBt_c_01.setSelected(true);
					ball_3rd_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		iBt_c_02 = (Button) findViewById(R.id.buy_pl3_c_02);
		iBt_c_02.setSelected(false);
		iBt_c_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_02.isSelected()) {
					iBt_c_02.setSelected(false);
					ball_3rd_dintInt.remove(2);

				} else {
					iBt_c_02.setSelected(true);
					ball_3rd_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		iBt_c_03 = (Button) findViewById(R.id.buy_pl3_c_03);
		iBt_c_03.setSelected(false);
		iBt_c_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_03.isSelected()) {
					iBt_c_03.setSelected(false);
					ball_3rd_dintInt.remove(3);

				} else {
					iBt_c_03.setSelected(true);
					ball_3rd_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		iBt_c_04 = (Button) findViewById(R.id.buy_pl3_c_04);
		iBt_c_04.setSelected(false);
		iBt_c_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_04.isSelected()) {
					iBt_c_04.setSelected(false);
					ball_3rd_dintInt.remove(4);

				} else {
					iBt_c_04.setSelected(true);
					ball_3rd_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		iBt_c_05 = (Button) findViewById(R.id.buy_pl3_c_05);
		iBt_c_05.setSelected(false);
		iBt_c_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_05.isSelected()) {
					iBt_c_05.setSelected(false);
					ball_3rd_dintInt.remove(5);

				} else {
					iBt_c_05.setSelected(true);
					ball_3rd_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		iBt_c_06 = (Button) findViewById(R.id.buy_pl3_c_06);
		iBt_c_06.setSelected(false);
		iBt_c_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_06.isSelected()) {
					iBt_c_06.setSelected(false);
					ball_3rd_dintInt.remove(6);

				} else {
					iBt_c_06.setSelected(true);
					ball_3rd_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
		iBt_c_07 = (Button) findViewById(R.id.buy_pl3_c_07);
		iBt_c_07.setSelected(false);
		iBt_c_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_07.isSelected()) {
					iBt_c_07.setSelected(false);
					ball_3rd_dintInt.remove(7);

				} else {
					iBt_c_07.setSelected(true);
					ball_3rd_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		iBt_c_08 = (Button) findViewById(R.id.buy_pl3_c_08);
		iBt_c_08.setSelected(false);
		iBt_c_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_08.isSelected()) {
					iBt_c_08.setSelected(false);
					ball_3rd_dintInt.remove(8);

				} else {
					iBt_c_08.setSelected(true);
					ball_3rd_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		iBt_c_09 = (Button) findViewById(R.id.buy_pl3_c_09);
		iBt_c_09.setSelected(false);
		iBt_c_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_c_09.isSelected()) {
					iBt_c_09.setSelected(false);
					ball_3rd_dintInt.remove(9);

				} else {
					iBt_c_09.setSelected(true);
					ball_3rd_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});
	}

	public void init_4th_ball() {

		ball_4th_dintInt = new DynArrayInt();

		iBt_d_00 = (Button) findViewById(R.id.buy_pl3_d_00);
		iBt_d_00.setSelected(false);
		iBt_d_00.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_00.isSelected()) {
					iBt_d_00.setSelected(false);
					ball_4th_dintInt.remove(0);

				} else {
					iBt_d_00.setSelected(true);
					ball_4th_dintInt.addInt(0);

				}
				getMoneyInfo();
			}
		});

		iBt_d_01 = (Button) findViewById(R.id.buy_pl3_d_01);
		iBt_d_01.setSelected(false);
		iBt_d_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_01.isSelected()) {
					iBt_d_01.setSelected(false);
					ball_4th_dintInt.remove(1);

				} else {
					iBt_d_01.setSelected(true);
					ball_4th_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		iBt_d_02 = (Button) findViewById(R.id.buy_pl3_d_02);
		iBt_d_02.setSelected(false);
		iBt_d_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_02.isSelected()) {
					iBt_d_02.setSelected(false);
					ball_4th_dintInt.remove(2);

				} else {
					iBt_d_02.setSelected(true);
					ball_4th_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		iBt_d_03 = (Button) findViewById(R.id.buy_pl3_d_03);
		iBt_d_03.setSelected(false);
		iBt_d_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_03.isSelected()) {
					iBt_d_03.setSelected(false);
					ball_4th_dintInt.remove(3);

				} else {
					iBt_d_03.setSelected(true);
					ball_4th_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		iBt_d_04 = (Button) findViewById(R.id.buy_pl3_d_04);
		iBt_d_04.setSelected(false);
		iBt_d_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_04.isSelected()) {
					iBt_d_04.setSelected(false);
					ball_4th_dintInt.remove(4);

				} else {
					iBt_d_04.setSelected(true);
					ball_4th_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		iBt_d_05 = (Button) findViewById(R.id.buy_pl3_d_05);
		iBt_d_05.setSelected(false);
		iBt_d_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_05.isSelected()) {
					iBt_d_05.setSelected(false);
					ball_4th_dintInt.remove(5);

				} else {
					iBt_d_05.setSelected(true);
					ball_4th_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		iBt_d_06 = (Button) findViewById(R.id.buy_pl3_d_06);
		iBt_d_06.setSelected(false);
		iBt_d_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_06.isSelected()) {
					iBt_d_06.setSelected(false);
					ball_4th_dintInt.remove(6);

				} else {
					iBt_d_06.setSelected(true);
					ball_4th_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
		iBt_d_07 = (Button) findViewById(R.id.buy_pl3_d_07);
		iBt_d_07.setSelected(false);
		iBt_d_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_07.isSelected()) {
					iBt_d_07.setSelected(false);
					ball_4th_dintInt.remove(7);

				} else {
					iBt_d_07.setSelected(true);
					ball_4th_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		iBt_d_08 = (Button) findViewById(R.id.buy_pl3_d_08);
		iBt_d_08.setSelected(false);
		iBt_d_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_08.isSelected()) {
					iBt_d_08.setSelected(false);
					ball_4th_dintInt.remove(8);

				} else {
					iBt_d_08.setSelected(true);
					ball_4th_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		iBt_d_09 = (Button) findViewById(R.id.buy_pl3_d_09);
		iBt_d_09.setSelected(false);
		iBt_d_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_d_09.isSelected()) {
					iBt_d_09.setSelected(false);
					ball_4th_dintInt.remove(9);

				} else {
					iBt_d_09.setSelected(true);
					ball_4th_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

	}

	public void init_5th_ball() {

		ball_5th_dintInt = new DynArrayInt();

		iBt_e_00 = (Button) findViewById(R.id.buy_pl3_e_00);
		iBt_e_00.setSelected(false);
		iBt_e_00.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_00.isSelected()) {
					iBt_e_00.setSelected(false);
					ball_5th_dintInt.remove(0);

				} else {
					iBt_e_00.setSelected(true);
					ball_5th_dintInt.addInt(0);

				}
				getMoneyInfo();
			}
		});

		iBt_e_01 = (Button) findViewById(R.id.buy_pl3_e_01);
		iBt_e_01.setSelected(false);
		iBt_e_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_01.isSelected()) {
					iBt_e_01.setSelected(false);
					ball_5th_dintInt.remove(1);

				} else {
					iBt_e_01.setSelected(true);
					ball_5th_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		iBt_e_02 = (Button) findViewById(R.id.buy_pl3_e_02);
		iBt_e_02.setSelected(false);
		iBt_e_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_02.isSelected()) {
					iBt_e_02.setSelected(false);
					ball_5th_dintInt.remove(2);

				} else {
					iBt_e_02.setSelected(true);
					ball_5th_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		iBt_e_03 = (Button) findViewById(R.id.buy_pl3_e_03);
		iBt_e_03.setSelected(false);
		iBt_e_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_03.isSelected()) {
					iBt_e_03.setSelected(false);
					ball_5th_dintInt.remove(3);

				} else {
					iBt_e_03.setSelected(true);
					ball_5th_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		iBt_e_04 = (Button) findViewById(R.id.buy_pl3_e_04);
		iBt_e_04.setSelected(false);
		iBt_e_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_04.isSelected()) {
					iBt_e_04.setSelected(false);
					ball_5th_dintInt.remove(4);

				} else {
					iBt_e_04.setSelected(true);
					ball_5th_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		iBt_e_05 = (Button) findViewById(R.id.buy_pl3_e_05);
		iBt_e_05.setSelected(false);
		iBt_e_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_05.isSelected()) {
					iBt_e_05.setSelected(false);
					ball_5th_dintInt.remove(5);

				} else {
					iBt_e_05.setSelected(true);
					ball_5th_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		iBt_e_06 = (Button) findViewById(R.id.buy_pl3_e_06);
		iBt_e_06.setSelected(false);
		iBt_e_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_06.isSelected()) {
					iBt_e_06.setSelected(false);
					ball_5th_dintInt.remove(6);

				} else {
					iBt_e_06.setSelected(true);
					ball_5th_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
		iBt_e_07 = (Button) findViewById(R.id.buy_pl3_e_07);
		iBt_e_07.setSelected(false);
		iBt_e_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_07.isSelected()) {
					iBt_e_07.setSelected(false);
					ball_5th_dintInt.remove(7);

				} else {
					iBt_e_07.setSelected(true);
					ball_5th_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		iBt_e_08 = (Button) findViewById(R.id.buy_pl3_e_08);
		iBt_e_08.setSelected(false);
		iBt_e_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_08.isSelected()) {
					iBt_e_08.setSelected(false);
					ball_5th_dintInt.remove(8);

				} else {
					iBt_e_08.setSelected(true);
					ball_5th_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		iBt_e_09 = (Button) findViewById(R.id.buy_pl3_e_09);
		iBt_e_09.setSelected(false);
		iBt_e_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (iBt_e_09.isSelected()) {
					iBt_e_09.setSelected(false);
					ball_5th_dintInt.remove(9);

				} else {
					iBt_e_09.setSelected(true);
					ball_5th_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

	}

	private void initText() {
		currentIssue = (TextView) findViewById(R.id.buy_pl3_currentissue);
		endTimeText = (TextView) findViewById(R.id.buy_pl3_endtime);
		endTimeText.setText("--------------");
		// modeDES = (TextView) findViewById(R.id.buy_pl3_mode_des);
		countText = (TextView) findViewById(R.id.buy_pl3_count);
		moneyText = (TextView) findViewById(R.id.buy_pl3_amount);
		moneyText.setText("0");
		countText.setText("0");
		tvJiangJin = (TextView) findViewById(R.id.tvJiangJin);
	}

	// Button初始化
	public void initButton() {
		buy_ssqxh_Button03 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button03);
		buy_ssqxh_Button04 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button04);
		buy_pl5_random = (Button) findViewById(R.id.buy_pl3_random);// 机选
		buy_pl5_clear = (Button) findViewById(R.id.buy_pl3_clear);// 清空选择
		buy_pl5_submit = (Button) findViewById(R.id.buy_pl3_submit);// 确认选择
	}

	public boolean checkUserLogin() {
		// app_pl5dto = (ApplicationBall) getApplication();
		if (!ApplicationData.getInstance().getLoginName().equals("")
				&& !ApplicationData.getInstance().getLoginPwd().equals("")
				|| !ApplicationData.getInstance().getUserID().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	// 显示注数和金钱
	public void getMoneyInfo() {
		int money;
		count = 0;
		switch (playTypeId) {
		case PL5_ZX_F:// 直选
			count = ball_1st_dintInt.getSize() * ball_2nd_dintInt.getSize() * ball_3rd_dintInt.getSize()
					* ball_4th_dintInt.getSize() * ball_5th_dintInt.getSize();
			break;

		}
		money = count * 2;
		allMoney = money;
		countText.setText(count + "");
		moneyText.setText(Html.fromHtml("<font color='#fe5052'>" + money + "</font>" + " 元"));
		// 计算总奖金
		// 奖金
		int totalmoney = 100000;
		if (money == 0) {
			tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
		} else {
			String strjiangjin = ".若中奖：奖金" + totalmoney + "元，盈利" + (totalmoney - money) + "元";
			tvJiangJin.setText(strjiangjin);
		}
		if (count == 0) {
			buy_ssq_llfoot0.setVisibility(View.VISIBLE);
			buy_ssq_rlfoot1.setVisibility(View.GONE);
		} else {
			buy_ssq_llfoot0.setVisibility(View.GONE);
			buy_ssq_rlfoot1.setVisibility(View.VISIBLE);
		}
	}

	// TitleBar标题栏
	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.pailie5_name);

		final Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.setBackgroundDrawable(null);
		refres.setText("帮助");
		// refres.setBackgroundResource(R.color.common_menu);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(Pailie5xhActivity.this);
				View menuview = inflater.inflate(R.layout.public_menulink, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setFocusable(true);
				m_popupWindow.setTouchable(true);
				m_popupWindow.setOutsideTouchable(false);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(refres);

				menuview.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LOT_ID_PL5);
							intent0.setClass(Pailie5xhActivity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_PL5);
						}
					}
				});

				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							intent = new Intent(getApplicationContext(), ZhRecordActivity.class);
							startActivity(intent);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_PL5);
						}
					}
				});
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						intent = new Intent(getApplicationContext(), KjinfoListByType.class);
						intent.putExtra("LottID", "64");
						intent.putExtra("LottName", getString(R.string.kjinfo_number_p5_info));
						startActivity(intent);
					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						// Intent intent = new Intent(getApplicationContext(),
						// HelpActivity.class);
						// startActivity(intent);
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "排列5");
						intent.putExtra("cp_url", "pl5.html");
						startActivity(intent);
					}
				});
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// 停止监听
			sensor.stop();
			if (ifbacklist) {
				Intent intent = new Intent();
				intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_pl5dto());
				intent.putExtra("PlayTypeID", playTypeId);
				intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_pl5money());
				intent.putExtra("LotID", lotID);
				intent.putExtra("Count", count);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.setClass(Pailie5xhActivity.this, Pailie5ListActivity.class);
				startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
			} else {
				if(ifPush){
					Intent intent = new Intent(this, JddMainActivity.class);
					startActivity(intent);
				}
				ApplicationData.getInstance().initList();
			}
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (requestCode == REQ_CODE_BUYMAIN && resultCode == RESULT_OK) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
		
		if(resultCode == RESULT_OK) {
		if(requestCode == REQ_CODE_BUY_LOGIN ) {
			goXhlbSubmit();
		}
		}
		// if (resultCode == RESULT_OK) {
		// onKeyDown(KeyEvent.KEYCODE_BACK, null);
		// }
	};

	private void goXhlbSubmit() {
		// TODO Auto-generated method stub

		// TODO Auto-generated method stub
		if (checkUserLogin()) {
			if (issueName == null || issueName.equals("")) {
				Toast.makeText(Pailie5xhActivity.this, R.string.is_retrieving_period_time, Toast.LENGTH_SHORT)
						.show();
				return;
			}
			if (allMoney > 0 && count > 0) {
				BallDTO pl5dto = new BallDTO();
				// 获得自定义的应用程序BallDTO
				// app_pl5dto = (ApplicationBall) getApplication();
				// 如果是直选
				if (playTypeId == PL5_ZX_F) {
					// 获取每位的长度
					int a = ball_1st_dintInt.getSize();
					int b = ball_2nd_dintInt.getSize();
					int c = ball_3rd_dintInt.getSize();
					int d = ball_4th_dintInt.getSize();
					int e = ball_5th_dintInt.getSize();
					String ball = "";
					if (a >= 1 && b >= 1 && c >= 1 && d >= 1 && e >= 1) {
						String first_ball = ball_1st_dintInt.getAllIntToStringForSingle(ball_1st_dintInt
								.getAllInt());
						first_ball = first_ball.substring(0, first_ball.length() - 1);

						String second_ball = ball_2nd_dintInt.getAllIntToStringForSingle(ball_2nd_dintInt
								.getAllInt());
						second_ball = second_ball.substring(0, second_ball.length() - 1);

						String third_ball = ball_3rd_dintInt.getAllIntToStringForSingle(ball_3rd_dintInt
								.getAllInt());
						third_ball = third_ball.substring(0, third_ball.length() - 1);

						String forth_ball = ball_4th_dintInt.getAllIntToStringForSingle(ball_4th_dintInt
								.getAllInt());
						forth_ball = forth_ball.substring(0, forth_ball.length() - 1);

						String fifth_ball = ball_5th_dintInt.getAllIntToStringForSingle(ball_5th_dintInt
								.getAllInt());
						fifth_ball = fifth_ball.substring(0, fifth_ball.length() - 1);
						// 排序
						first_ball = DynArrayInt.sortBall(first_ball);
						second_ball = DynArrayInt.sortBall(second_ball);
						third_ball = DynArrayInt.sortBall(third_ball);
						forth_ball = DynArrayInt.sortBall(forth_ball);
						fifth_ball = DynArrayInt.sortBall(fifth_ball);
						ball = first_ball + "|" + second_ball + "|" + third_ball + "|" + forth_ball + "|"
								+ fifth_ball;

						sendIntent(pl5dto, ball);

					} else {
						Toast.makeText(Pailie5xhActivity.this, R.string.need_to_select_at_least_one_number,
								Toast.LENGTH_SHORT).show();
					}
				}
			} else {
				// if
				// (ApplicationData.getInstance().getList_pl3dto().size()
				// == 0) {
				Toast.makeText(Pailie5xhActivity.this, R.string.select_a_valid_bets_number, Toast.LENGTH_SHORT)
						.show();
				// } else {
				// Intent intent = new Intent();
				// intent.putExtra("list_elvdto",
				// ApplicationData.getInstance().getList_pl3dto());
				// intent.putExtra("PlayTypeID", playTypeId);
				// // intent.putExtra("PlayType",
				// playType.getSelectedItem().toString());
				// intent.putExtra("AllMoney",
				// ApplicationData.getInstance().getAll_pl3money());
				// intent.putExtra("LotID", lotID);
				// intent.putExtra("Count", count);
				// intent.putExtra("IssueID", issueID);
				// intent.putExtra("IssueName", issueName);
				// intent.setClass(Pailie5xhActivity.this,
				// Pailie5ListActivity.class);
				// startActivityForResult(intent,
				// REQ_CODE_BUYMAIN);//(intent);
				// }
			}
		} else {
			Intent intent = new Intent();
			intent.setClass(Pailie5xhActivity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
		}
	
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		sensor.stop();
		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		sensor.start();
		
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		handler.removeCallbacks(runnable);
		super.onDestroy();
	}

}
